package com.sy.controller.settings;

import com.sy.bean.settings.Dictionary;
import com.sy.common.bean.ResultBean;
import com.sy.common.controller.BaseController;
import com.sy.service.settings.DictionaryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Api(tags = "字典设置")
@RestController
@RequestMapping("/api")
public class DictionaryController extends BaseController {

    @Autowired
    DictionaryService dictionaryService;

    @ApiOperation("字典查询")
    @PostMapping("/dictionary")
    public ResultBean queryDict(@RequestParam(value = "code") String code){
        List list=dictionaryService.queryDict(code);
        return success("查询成功",list);
    }

    @ApiOperation("添加字典")
    @PostMapping("/dictionary/save")
    public ResultBean saveDict(@RequestBody Dictionary dictionary){
        int rs=dictionaryService.saveDict(dictionary);
        return gotoResult(rs,"保存");
    }

    @ApiOperation("修改")
    @PutMapping("/dictionary")
    public ResultBean updateDict(@RequestBody Dictionary dictionary){
        int rs=dictionaryService.updateDict(dictionary);
        return gotoResult(rs,"修改");
    }

    @ApiOperation("删除")
    @DeleteMapping("/dictionary")
    public ResultBean delDict(int id){
        int rs=dictionaryService.delDict(id);
        return gotoResult(rs,"删除");
    }
}
